package com.suep.system.controller;

import com.suep.system.config.BaseR;
import com.suep.system.domain.Menu;
import com.suep.system.domain.Role;
import com.suep.system.service.IMenuService;
import com.suep.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IRoleService roleService;
    @GetMapping("/getUserMenu")
    public BaseR<List<Menu>> getMenuByRoleId(HttpServletRequest request){
        String roleName=(String)request.getAttribute("role");
        if(roleName==null){
            return new BaseR<>().error("角色信息异常");
        }
        Role role=roleService.selectRoleByName(roleName);
        return new BaseR<>().ok("菜单获取成功", menuService.selectMenuByRoleId(role.getId()));
    }

//    @PostMapping
//    public BaseR<List<Menu>> createMenu(HttpServletRequest request){
//        return new BaseR<>().ok("菜单插入成功", menuService.);
//    }

}
